<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>学童日程管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="学童,日程,管理">
	<meta http-equiv="description" content="This is my page">

	<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/common/arrange/css/fullcalendar.css">
	<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/common/arrange/css/fullcalendar.print.css media='print'">
	<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/common/arrange/css/theme.css">
	<script type="text/javascript" src="${CONTEXT_PATH}/common/arrange/js/fullcalendar.js"></script>
	
	<style type='text/css'>
	body {
		text-align: center;
		font-size: 13px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
	}

	#calendar {
		width: 560px;
		margin: 0 auto;
	}

	</style>
  </head>
  
  <body>
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<s:hidden name="cavo.start" id="startDate"></s:hidden>
    		<s:hidden name="cavo.end" id="endDate"></s:hidden>
    		<s:hidden name="cavo.childId" id="childId"></s:hidden>
    		
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'学童管理'},{'name':'安排管理'},{'name':'${child.childName}'}]"/>
    			<jsp:param name="width" value="40%"/>
    		</jsp:include>
    		
    		<div id='calendar'></div>
    	</s:form>
    </center>
    
    <script type='text/javascript'>
	var arrangeId = '';
	var ev = null;
	var calendar;
	$(document).ready(function() {
	
		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();
		
		calendar = $('#calendar').fullCalendar({
			theme: true,
			header: {
				left: 'prevYear prev,next nextYear today',
				center: 'title',
				right: ''
			},
			events: function(start, end, callback) {
				var sDate = toDateStr(start);
				var eDate = toDateStr(end);
				$('#startDate').val(sDate);
				$('#endDate').val(eDate);
				ajaxAction('inner/common/queryChildArrangeList.action', 'post', 'frm', true, function(list){
					var events = [];
					var len = list.length;
					for(var i = 0; i < len; i++)
					{
						events.push({id:list[i].id, title:list[i].title, start:list[i].arrangeDate});
					}
					callback(events);
				});
			},
			dayClick:function(date, allDay, jsEvent, view) {
				hideMenu();
				var d = toDateStr(date);
				var childId = $('#childId');
				var url = realPath + '/inner/common/toAddChildArrange.action?ca.child.id=' + childId.val() + '&ca.arrangeDate=' + d;
				var ca = showMd(url, 550, 360, 'yes', 'yes');
				if(ca != null && ca != undefined)
				{
					calendar.fullCalendar('refetchEvents');
				}
			},
			eventClick: function(calEvent, jsEvent, view) {
				arrangeId = calEvent.id;
				ev = calEvent;
				showMenu(jsEvent);
			}
		});
		
	});
	
	function showMenu(e)
	{
		var menuDiv = $('#menuDiv');
		menuDiv.css({'display':'block', 'left':e.clientX, 'top':e.clientY + 12});
	}
	function hideMenu()
	{
		var menuDiv = $('#menuDiv');
		menuDiv.css('display', 'none');
	}
	
	function toUpdateChildArrange()
	{
		hideMenu();
		var url = realPath + '/inner/common/toUpdateChildArrange.action?ca.id=' + arrangeId;
		var ca = showMd(url, 550, 360, 'yes', 'yes');
		if(ca != null && ca != undefined)
		{
			if(ev != null)
			{
				ev.title = ca.title;
				calendar.fullCalendar('updateEvent', ev);
			}
		}
	}
	
	function delChildArrange()
	{
		hideMenu();
		showConfirm('确认删除？', function(v){
			if(v == true)
			{
				var url = 'inner/common/delChildArrange.action?ca.id=' + arrangeId;
				ajaxAction(url, 'get', 'frm', false, function(){
					calendar.fullCalendar('removeEvents', arrangeId);
				});
			}
		});
	}

</script>

	<div style="position:absolute; display:none;" id="menuDiv">
		<table width="60px" cellpadding="2" cellspacing="1" bgcolor="lightblue">
			<tr class="tableRow1">
				<td align="right" height="20px">
					<a href="javascript:hideMenu()" style="font-size:12px;">关闭</a>
				</td>
			</tr>
			<tr bgcolor="#FFFFFF">
				<td align="left" style="cursor:hand;" onclick="toUpdateChildArrange()">
					查看
				</td>
			</tr>
			<tr bgcolor="#FFFFFF">
				<td align="left" style="cursor:hand;" onclick="delChildArrange()">
					删除
				</td>
			</tr>
		</table>
	</div>
  </body>
</html>
